package com.blog.controller;

import com.blog.service.ArticleService;
import com.blog.service.TagService;
import com.blog.service.impl.ArticleServiceImpl;
import com.blog.service.impl.TagServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/EditTagServlet.do")
public class EditTagServlet extends HttpServlet {
    TagService tagService=new TagServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        try {
            int count = tagService.editTag(req.getParameter("tagName"),req.getParameter("newTag"));
            if(count==0){
                resp.getWriter().write("<script>alert('标签修改失败！');location.href='/Blog/GoAdminServlet.do';</script>");
            }else {
                resp.getWriter().write("<script>alert('标签修改成功！');location.href='/Blog/GoAdminServlet.do';</script>");
            }
        } catch (Exception e) {
            e.printStackTrace();
            resp.getWriter().write("<script>alert('标签修改异常！');location.href='/Blog/GoAdminServlet.do';</script>");
        }
    }
}
